import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import { TRAP_FOCUS_HANDLER } from 'element-plus/es/directives/trap-focus/index.mjs'

// https://vite.dev/config/
export default defineConfig({
  server: {
    host: '0.0.0.0',
    port: '5173',
    strictPort: TRAP_FOCUS_HANDLER, // 强制使用指定的端口
    allowedHosts: ['x3c6992f.natappfree.cc'],
    open: true, // 在启动时打开浏览器
    // hmr: {
    //   protocol: 'ws',
    //   host: 'x3c6992f.natappfree.cc' // 必须与访问域名一致
    // }
  },
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
